import delimited "./ipeds/2006/hd2006.csv", stringcols(12 13 14) clear 

gen year=2006

keep ein sector iclevel control hloffer hdegoffr deggrant ccipgrad ccbasic carnegie

destring ein, generate(num_ein) force
drop if num_ein<0
drop if missing(num_ein)
drop num_ein

drop if deggrant==4

duplicates tag ein, gen(dup)
gen is_n_m3 = (carnegie!=-3)
bys ein: egen has_n_m3 = total(is_n_m3)
drop if has_n_m3>0 & is_n_m3==0 & dup>0
drop has_n_m3 is_n_m3 dup

duplicates drop
foreach num of numlist 15 16 21 22 31 {
duplicates tag ein, gen(dup)
gen is_`num' = (carnegie==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_m3 = (carnegie!=-3)
bys ein: egen has_n_m3 = total(is_n_m3)
drop if has_n_m3>0 & is_n_m3==0 & dup>0
drop has_n_m3 is_n_m3 dup

foreach num of numlist 15(1)23 {
duplicates tag ein, gen(dup)
gen is_`num' = (ccbasic==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_m3 = (ccbasic!=-3)
bys ein: egen has_n_m3 = total(is_n_m3)
drop if has_n_m3>0 & is_n_m3==0 & dup>0
drop has_n_m3 is_n_m3 dup

foreach num of numlist 14 15 17 18 16 13 12 4 5 {
duplicates tag ein, gen(dup)
gen is_`num' = (ccipgrad==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_m2 = (ccipgrad>0)
bys ein: egen has_n_m2 = total(is_n_m2)
drop if has_n_m2>0 & is_n_m2==0 & dup>0
drop has_n_m2 is_n_m2 dup

duplicates drop
foreach num of numlist 1 2 {
duplicates tag ein, gen(dup)
gen is_`num' = (deggrant==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

foreach num of numlist 9(1)2 {
duplicates tag ein, gen(dup)
gen is_`num' = (hloffer==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_0 = (sector==0)
bys ein: egen has_0 = total(is_0)
drop if has_0>0 & is_0==0 & dup>0
drop has_0 is_0 dup

duplicates tag ein, gen(dup)
gen is_n_m3 = (hdegoffr!=-3)
bys ein: egen has_n_m3 = total(is_n_m3)
drop if has_n_m3>0 & is_n_m3==0 & dup>0
drop has_n_m3 is_n_m3 dup

foreach num of numlist 11 10 21 20 31 30 {
duplicates tag ein, gen(dup)
gen is_`num' = (hdegoffr==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_3 = (control!=3)
bys ein: egen has_n_3 = total(is_n_3)
drop if has_n_3>0 & is_n_3==0 & dup>0
drop has_n_3 is_n_3 dup

foreach num of numlist 32 33 40 {
duplicates tag ein, gen(dup)
gen is_`num' = (carnegie==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

*Random
gen runiform = runiform()
sort ein carnegie runiform ccbasic ccipgrad
duplicates drop ein, force
drop  runiform

label variable ein "Employer Identification Number"
label variable sector "Sector of institution"
label variable iclevel "Level of institution"
label variable control "Control of institution"
label variable hloffer "Highest level of offering"
label variable hdegoffr "Highest degree offered"
label variable deggrant "Degree granting status"
label variable ccipgrad "Carnegie Classification 2005: Graduate Instructional Program"
label variable ccbasic  "Carnegie Classification 2005/2010: Basic"
label variable carnegie "Carnegie Classification 2000"

label define label_sector 0 "Central office or Administrative Unit" 
label define label_sector 1 "4-year public", add 
label define label_sector 2 "4-year private, not-for-profit", add 
label define label_sector 3 "4-year private, for-profit", add 
label define label_sector 4 "2-year public", add 
label define label_sector 5 "2-year private, not-for-profit", add 
label define label_sector 6 "2-year private, for-profit", add 
label define label_sector 7 "Less than 2-year public", add 
label define label_sector 8 "Less than 2-year private, not-for-profit", add 
label define label_sector 9 "Less than 2-year private, for-profit", add 
label define label_sector 99 "sector not known", add 
label values sector label_sector

label define label_iclevel -3 "{Not available}" 
label define label_iclevel 1 "Four or more years", add 
label define label_iclevel 2 "At least 2 but less than 4 years", add 
label define label_iclevel 3 "Less than 2 years (below associate)", add 
label values iclevel label_iclevel

label define label_control -3 "{Not available}" 
label define label_control 1 "Public", add 
label define label_control 2 "Private, not-for-profit", add 
label define label_control 3 "Private, for-profit", add 
label values control label_control

label define label_hloffer -2 "{Not applicable, first-professional only}" 
label define label_hloffer -3 "{Not available}", add 
label define label_hloffer 0 "Other", add 
label define label_hloffer 1 "Award of less than one academic year", add 
label define label_hloffer 2 "At least 1, but less than 2 academic yea", add 
label define label_hloffer 3 "Associates degree", add 
label define label_hloffer 4 "At least 2, but less than 4 academic yea", add 
label define label_hloffer 5 "Bachelors degree", add 
label define label_hloffer 6 "Postbaccalaureate certificate", add 
label define label_hloffer 7 "Masters degree", add 
label define label_hloffer 8 "Post-masters certificate", add 
label define label_hloffer 9 "Doctors degree", add 
label values hloffer label_hloffer

label define label_hdegoffr 0 "Non-degree granting"
label define label_hdegoffr 1 "First-professional only",add
label define label_hdegoffr 10 "Doctoral",add
label define label_hdegoffr 11 "Doctoral and first-professional",add
label define label_hdegoffr 20 "Masters",add
label define label_hdegoffr 21 "Masters and first-professional",add
label define label_hdegoffr 30 "Bachelors",add
label define label_hdegoffr 31 "Bachelors and first-professional",add
label define label_hdegoffr 40 "Associates",add
label define label_hdegoffr -3 "{Not available}",add
label values hdegoffr label_hdegoffr

label define label_deggrant -3 "{Not available}" 
label define label_deggrant 1 "Degree-granting", add 
label define label_deggrant 2 "Nondegree-granting, primarily postsecond", add 
label define label_deggrant 3 "Not primarily postsecondary institutions", add 
label define label_deggrant 4 "Institution is not an educational entity", add 
label values deggrant label_deggrant

label define label_ccipgrad 1 "Single postbaccalaureate (education)"
label define label_ccipgrad 2 "Single postbaccalaureate (business)",add
label define label_ccipgrad 3 "Single postbaccalaureate (other field)",add
label define label_ccipgrad 4 "Postbaccalaureate comprehensive",add
label define label_ccipgrad 5 "Postbaccalaureate, arts & sciences dominant",add
label define label_ccipgrad 6 "Postbaccalaureate with arts & sciences (education dominant)",add
label define label_ccipgrad 7 "Postbaccalaureate with arts & sciences (business dominant)",add
label define label_ccipgrad 8 "Postbaccalaureate with arts & sciences (other dominant fields)",add
label define label_ccipgrad 9 "Postbaccalaureate professional (education dominant)",add
label define label_ccipgrad 10 "Postbaccalaureate professional (business dominant)",add
label define label_ccipgrad 11 "Postbaccalaureate professional (other dominant fields)",add
label define label_ccipgrad 12 "Single doctoral (education)",add
label define label_ccipgrad 13 "Single doctoral (other field)",add
label define label_ccipgrad 14 "Comprehensive doctoral with medical/veterinary",add
label define label_ccipgrad 15 "Comprehensive doctoral (no medical/veterinary)",add
label define label_ccipgrad 16 "Doctoral, humanities/social sciences dominant",add
label define label_ccipgrad 17 "STEM dominant",add
label define label_ccipgrad 18 "Doctoral, professional dominant",add
label define label_ccipgrad -1 "Not applicable",add
label define label_ccipgrad -2 "Not applicable, special focus institution",add
label define label_ccipgrad -3 "Not applicable, not in Carnegie universe (not accredited or nondegree-granting)",add
label values ccipgrad label_ccipgrad

label define label_ccbasic 1 "Associate^s--Public Rural-serving Small"
label define label_ccbasic 2 "Associate^s--Public Rural-serving Medium",add
label define label_ccbasic 3 "Associate^s--Public Rural-serving Large",add
label define label_ccbasic 4 "Associate^s--Public Suburban-serving Single Campus",add
label define label_ccbasic 5 "Associate^s--Public Suburban-serving Multicampus",add
label define label_ccbasic 6 "Associate^s--Public Urban-serving Single Campus",add
label define label_ccbasic 7 "Associate^s--Public Urban-serving Multicampus",add
label define label_ccbasic 8 "Associate^s--Public Special Use",add
label define label_ccbasic 9 "Associate^s--Private Not-for-profit",add
label define label_ccbasic 10 "Associate^s--Private For-profit",add
label define label_ccbasic 11 "Associate^s--Public 2-year colleges under 4-year universities",add
label define label_ccbasic 12 "Associate^s--Public 4-year Primarily Associate^s",add
label define label_ccbasic 13 "Associate^s--Private Not-for-profit 4-year Primarily Associate^s",add
label define label_ccbasic 14 "Associate^s--Private For-profit 4-year Primarily Associate^s",add
label define label_ccbasic 15 "Research Universities (very high research activity)",add
label define label_ccbasic 16 "Research Universities (high research activity)",add
label define label_ccbasic 17 "Doctoral/Research Universities",add
label define label_ccbasic 18 "Master^s Colleges and Universities (larger programs)",add
label define label_ccbasic 19 "Master^s Colleges and Universities (medium programs)",add
label define label_ccbasic 20 "Master^s Colleges and Universities (smaller programs)",add
label define label_ccbasic 21 "Baccalaureate Colleges--Arts & Sciences",add
label define label_ccbasic 22 "Baccalaureate Colleges--Diverse Fields",add
label define label_ccbasic 23 "Baccalaureate/Associate^s Colleges",add
label define label_ccbasic 24 "Theological seminaries, Bible colleges, and other faith-related institutions",add
label define label_ccbasic 25 "Medical schools and medical centers",add
label define label_ccbasic 26 "Other health professions schools",add
label define label_ccbasic 27 "Schools of engineering",add
label define label_ccbasic 28 "Other technology-related schools",add
label define label_ccbasic 29 "Schools of business and management",add
label define label_ccbasic 30 "Schools of art, music, and design",add
label define label_ccbasic 31 "Schools of law",add
label define label_ccbasic 32 "Other special-focus institutions",add
label define label_ccbasic 33 "Tribal Colleges",add
label define label_ccbasic -3 "Not applicable, not in Carnegie universe (not accredited or nondegree-granting)",add
label values ccbasic label_ccbasic

label define label_carnegie 15 "Doctoral/Research Universities--Extensive"
label define label_carnegie 16 "Doctoral/Research Universities--Intensive",add
label define label_carnegie 21 "Masters Colleges and Universities I",add
label define label_carnegie 22 "Masters Colleges and Universities II",add
label define label_carnegie 31 "Baccalaureate Colleges--Liberal Arts",add
label define label_carnegie 32 "Baccalaureate Colleges--General",add
label define label_carnegie 33 "Baccalaureate/Associates Colleges",add
label define label_carnegie 40 "Associates Colleges",add
label define label_carnegie 51 "Theological seminaries and other specialized faith-related institutions",add
label define label_carnegie 52 "Medical schools and medical centers",add
label define label_carnegie 53 "Other separate health profession schools",add
label define label_carnegie 54 "Schools of engineering and technology",add
label define label_carnegie 55 "Schools of business and management",add
label define label_carnegie 56 "Schools of art, music, and design",add
label define label_carnegie 57 "Schools of law",add
label define label_carnegie 58 "Teachers colleges",add
label define label_carnegie 59 "Other specialized institutions",add
label define label_carnegie 60 "Tribal colleges",add
label define label_carnegie -3 "{Item not available}",add
label values carnegie label_carnegie

save "./ipeds/2006/uni2006", replace

